package com.sailorj.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sailorj.medical.domain.chronicdis.Chronicdis;
import com.sailorj.medical.domain.medical.Medical;

/**
 * 医疗机构管理控制处理模块
 */
public class MedicalServlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String m = request.getParameter("m");// 动作类型参数
		if ("list".equals(m)) {
			process(request, response, "/page/medical/medical_list.jsp");
		} else if ("input".equals(m)) {
			process(request, response, "/page/medical/medical_add.jsp");
		} else if ("get".equals(m)) {
			process(request, response, "/page/medical/medical_edit.jsp");
		} else if ("add".equals(m)) {
			add(request, response);
			process(request, response, "/page/medical/medical_list.jsp");
		} else if ("edit".equals(m)) {
			edit(request, response);
		} else if ("del".equals(m)) {
			del(request, response);
		}

	}

	private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 接收页面传递过来的参数
		String jgbm = request.getParameter("jgbm");
		String zzjgbm = request.getParameter("zzjgbm");
		String jgmc = request.getParameter("jgmc");
		String dqbm = request.getParameter("dqbm");
		String areacode = request.getParameter("areacode");
		String lsgx = request.getParameter("lsgx");
		String jgjb = request.getParameter("jgjb");
		String sbddlx = request.getParameter("sbddlx");
		String pzddlx = request.getParameter("pzddlx");
		String ssjjlx = request.getParameter("ssjjlx");
		String wsjgdl = request.getParameter("wsjgdl");
		String wsjgxl = request.getParameter("wsjgxl");
		String zgdw = request.getParameter("zgdw");
		String kysj = request.getParameter("kysj");// 日期
		String frdb = request.getParameter("frdb");
		String zczjnum = request.getParameter("zczj");// 数值
		double zczj = Double.parseDouble(zczjnum);

		// 调用添加方法
		try {
			Medical model = new Medical(jgbm, zzjgbm, jgmc, dqbm, areacode, lsgx, jgjb, sbddlx, pzddlx, ssjjlx, wsjgdl,
					wsjgxl, zgdw, kysj, frdb, zczj);
			model.add();
		} catch (Exception e) {

			error(request, response);
		}

	}

	private void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{

		String jgbm = request.getParameter("jgbm");
		String zzjgbm = request.getParameter("zzjgbm");
		String jgmc = request.getParameter("jgmc");
		String dqbm = request.getParameter("dqbm");
		String areacode = request.getParameter("areacode");
		String lsgx = request.getParameter("lsgx");
		String jgjb = request.getParameter("jgjb");
		String sbddlx = request.getParameter("sbddlx");
		String pzddlx = request.getParameter("pzddlx");
		String ssjjlx = request.getParameter("ssjjlx");
		String wsjgdl = request.getParameter("wsjgdl");
		String wsjgxl = request.getParameter("wsjgxl");
		String zgdw = request.getParameter("zgdw");
		String kysj = request.getParameter("kysj");// 日期
		String frdb = request.getParameter("frdb");
		String zczjnum = request.getParameter("zczj");// 数值
		double zczj = Double.parseDouble(zczjnum);
		try{
			Medical model = new Medical(jgbm, zzjgbm, jgmc, dqbm, areacode, lsgx, jgjb, sbddlx, pzddlx, ssjjlx, wsjgdl,
					wsjgxl, zgdw, kysj, frdb, zczj);
			model.edit();
			process(request, response, "/page/medical/medical_list.jsp");
		}catch(Exception e){
			error(request, response);
		}


	}
	private void del(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{

		//1：接收参数
		String jgbm=req.getParameter("id");

		//2:构造新慢病信息对象
		Medical model = new Medical();
		try{
			model.del(jgbm);
			process(req, resp, "/page/medical/medical_list.jsp");
		}catch(Exception e){
			error(req, resp);
		}


	}

}
